from openpyxl.reader.excel import load_workbook
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from config.config import DRIVER_PATH
from pages.base_page import BasePage
from selenium.webdriver.common.by import By
from openpyxl import load_workbook


def chrome():
    server = Service(DRIVER_PATH)
    driver = webdriver.Chrome(service=server)
    return driver

class Tada(BasePage):
    #定位器
    log_data_locator = (By.ID,'data')
    tr_locator = (By.TAG_NAME,'tr')
    td_locator = (By.TAG_NAME,'td')
    #循坏表格
    def taba_find(self,tr,td=0):
        tada = self.driver.find_element(*self.log_data_locator)
        trs = tada.find_elements(*self.tr_locator)
        last_tr = trs[tr-1]
        tds = last_tr.find_elements(*self.td_locator)
        first_td = tds[td]
        last = (By.TAG_NAME,'input')
        first_td.find_element(*last).click()

    def read_excel(self,filename):
        # 打开excel文件
        wordbook = load_workbook(filename=filename)
        # 返回指定的页（shell）
        sheet = wordbook['crm']
        # 读取操作
        return list(sheet.iter_rows(values_only=True, min_row=2))

